#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

int main(int argc,char** argv)
{
    int state = 0;
    int ledCurrentState;
    if(argc != 2)
    {
        printf("usage: %s <on/off>\n",argv[0]);
        return -1;
    }

    if(strcmp(argv[1], "on") == 0)
    {
        state = 1;
    }
    else if(strcmp(argv[1], "off") == 0)
    {
        state = 0;
    }
    else
    {
        printf("usage: %s <on/off>\n",argv[0]);
        return -1;
    }

    int fd = open("/dev/led1",O_RDWR);
    write(fd, &state, sizeof(state));
    read(fd, &ledCurrentState, sizeof(ledCurrentState));
    printf("led1 is %s\n", ledCurrentState? "on" : "off");
    close(fd);
}